package freshmanspecial.mredrock.com.welcomefreshman.Fragment;

import android.graphics.Color;
import android.util.Log;
import android.view.View;
import android.widget.TextView;

import com.bigkoo.pickerview.OptionsPickerView;

import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.List;

import freshmanspecial.mredrock.com.welcomefreshman.Base.BaseFragment;
import freshmanspecial.mredrock.com.welcomefreshman.Bean.CircleChartData;
import freshmanspecial.mredrock.com.welcomefreshman.Bean.WorkRatioBean;
import freshmanspecial.mredrock.com.welcomefreshman.Model.DataModel;
import freshmanspecial.mredrock.com.welcomefreshman.MyChart.CircleChart;
import freshmanspecial.mredrock.com.welcomefreshman.R;

/**
 * Created by Administrator on 2017/8/3 0003.
 */

public class DataFragmentThree extends BaseFragment {
    private List<CircleChartData> defaultDatas = new ArrayList<>();
    private static List<String> options1Items = new ArrayList<>();
    private CircleChart chart;
    private TextView mTView;
    private OptionsPickerView pvOptions;
    CircleChartData data1,data2;
    DecimalFormat decimalFormat = new DecimalFormat(".00");

    @Override
    protected void addDefaultData() {
        defaultDatas.clear();
        data1 = new CircleChartData();
        data1.setProportion((float) 0.50);
        data1.setCircleColor(Color.parseColor("#B9E5FE"));
        data1.setCircleStrokeColor(Color.parseColor("#7AC8EF"));
        data1.setBackgroundColor(Color.parseColor("#F8FCFF"));
        data1.setBackgroundStrokeColor(Color.parseColor("#D4F5FF"));

        data2 = new CircleChartData();
        data2.setProportion((float) 0.60);
        data2.setCircleColor(Color.parseColor("#9EFCEE"));
        data2.setCircleStrokeColor(Color.parseColor("#6CEAD5"));
        data2.setBackgroundColor(Color.parseColor("#F8FFFE"));
        data2.setBackgroundStrokeColor(Color.parseColor("#D7FFF9"));

        defaultDatas.add(data1);
        defaultDatas.add(data2);
    }
    private void setupViews() {
        mTView = $(R.id.tv_value3);
        mTView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                pvOptions.show();
            }
        });

    }
    @Override
    protected void initView() {
        chart = $(R.id.working_circle);
        chart.setCircleChartData(defaultDatas);
        setupViews();
        setOptionsPicker();
    }
    private void addData(float workRatio,float unWorkRatio){
        defaultDatas.clear();
        data2.setProportion(workRatio);
        data1.setProportion(unWorkRatio);
        defaultDatas.add(data1);
        defaultDatas.add(data2);
        chart.setCircleChartData(defaultDatas);
    }
    @Override
    protected int getResourceId() {
        return R.layout.special_2017_data_work_fragment;
    }
    private void setOptionsPicker() {
        options1Items.clear();
        options1Items.add("通信与信息工程学院");
        options1Items.add("光电工程学院");
        options1Items.add("经济管理学院");
        options1Items.add("计算机科学与技术学院");
        options1Items.add("外国语学院");
        options1Items.add("生物信息学院");
        options1Items.add("网络空间安全与信息法学院");
        options1Items.add("自动化学院");
        options1Items.add("先进制造工程学院");
        options1Items.add("体育学院");
        options1Items.add("理学院");
        options1Items.add("传媒艺术学院");
        options1Items.add("软件工程学院");
        options1Items.add("国际半导体学院");
        options1Items.add("国际学院");
        DataModel dataModel = new DataModel();
        dataModel.getWorkRatio(new DataModel.OnGetData() {
            @Override
            public void onFinish(final Object dataBean) {
                final WorkRatioBean bean = (WorkRatioBean) dataBean;
                pvOptions = new  OptionsPickerView.Builder(getActivity(), new OptionsPickerView.OnOptionsSelectListener() {
                    @Override
                    public void onOptionsSelect(int options1, int option2, int options3 ,View v) {
                        //返回的分别是三个级别的选中位置
                        String s =  options1Items.get(options1);
                        mTView.setText("    "+s);
                        int x = 0;
                        for(int i=0;i<bean.getData().size();i++){
                            if (bean.getData().get(i).getCollege().equals(s))
                            {
                                x = 1;
                                float workRatio = Float.valueOf(bean.getData().get(i).getRatio());
                                float unWorkRatio = 1 - workRatio;
                                addData(Float.valueOf(decimalFormat.format(workRatio)),Float.valueOf(decimalFormat.format(unWorkRatio)));
                            }
                        }
                        if(x == 0){addData(0,0);}
                    }
                })
                        .setSubmitText("确定")//确定按钮文字
                        .setCancelText(" ")//取消按钮文字
                        .setSubCalSize(18)//确定和取消文字大小
                        .setSubmitColor(Color.parseColor("#81C0FE"))//确定按钮文字颜色
                        .setTitleBgColor(Color.parseColor("#00000000"))//标题背景颜色 Night mode
                        .setContentTextSize(18)//滚轮文字大小
                        .setTextColorCenter(Color.WHITE)//设置选中项的颜色
                        .setTextColorOut(Color.parseColor("#81C0FE"))
                        .isCenterLabel(true) //是否只显示中间选中项的label文字，false则每项item全部都带有label。
                        .setOutSideCancelable(true)//点击外部dismiss default true
                        .build();
                pvOptions.setPicker(options1Items);
            }
        });
    }
}
